package com.qyer.search.model.mutable;

import java.util.*;

/**
 * Created by tangzheng on 16/8/12.
 */
public class IndexMap<T> {
  private int indexNum;
  private List<Map<Integer,T>> listMap;

  private int size;
  public IndexMap(int indexNum) {
    this.indexNum = indexNum;
    this.listMap = new ArrayList<>(indexNum);
    for(int i = 0; i < indexNum; i++){
      listMap.add(new HashMap<Integer, T>(1000));
    }
    size = 0;
  }

  public T put(int id,T o){
    int indexId = id % indexNum;
    size++;
    return listMap.get(indexId).put(id, o);
  }

  public boolean containsKey(int id){
    int indexId = id % indexNum;
    return listMap.get(indexId).containsKey(id);
  }

  public T get(int id){
    int indexId = id % indexNum;
    return listMap.get(indexId).get(id);
  }

  public int size(){
    return this.size;
  }

}
